package com.qth.valet.common.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.HttpClientConfig;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.qth.valet.payment.SmsConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class AliyunSmsConfig {

    @Resource
    private SmsConfig smsConfig;

    @Bean
    public IAcsClient acsClient() {
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                smsConfig.getAccessKeyId(),
                smsConfig.getAccessKeySecret());

        /*DefaultProfile.addEndpoint("cn-hangzhou",
                smsConfig.getProduct(), smsConfig.getDomain());*/

        // 创建 HTTP 客户端配置
        HttpClientConfig clientConfig = HttpClientConfig.getDefault();
        clientConfig.setConnectionTimeoutMillis(5000); // 连接超时：5秒（毫秒）
        clientConfig.setReadTimeoutMillis(10000);      // 读取超时：10秒（毫秒）

        // 将配置应用到 Profile
        profile.setHttpClientConfig(clientConfig);

        return new DefaultAcsClient(profile);
    }
}

